package com.augurit.gzcgwsp.jzfqwczz.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.common.convert.WfBusClientBaseInfoConvertor;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.jzfqwczz.entity.YwYnJzfqwczcJbxx;
import com.augurit.gzcgwsp.jzfqwczz.web.form.YwYnJzfqwczcJbxxForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwYnJzfqwczcJbxxForFx;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

public class YwYnJzfqwczcJbxxConvertor {
	public static YwYnJzfqwczcJbxxForm convertVoToForm(YwYnJzfqwczcJbxx entity) {
		if(entity != null) {
			YwYnJzfqwczcJbxxForm form = new DozerBeanMapper().map(entity, YwYnJzfqwczcJbxxForm.class);
			form.setCzzFzr(entity.getCzzFzr());
			form.setCzzFzsj(entity.getCzzFzsj());
			form.setId(entity.getId());
			form.setAcceptNo(entity.getAcceptNo());
			form.setApprovalNo(entity.getApprovalNo());
			form.setSqDate(entity.getSqDate());
			form.setFrxm(entity.getFrxm());
			form.setFrphone(entity.getFrphone());
			form.setAddress(entity.getAddress());
			form.setSqsx(entity.getSqsx());
			form.setCzzh(entity.getCzzh());
			form.setQymcSimpl(entity.getQymcSimpl());
			form.setPost(entity.getPost());
			form.setQyphone(entity.getQyphone());
//			form.setFrName(entity.getFrName());
			form.setFrTel(entity.getFrTel());
			form.setYwlxr(entity.getYwlxr());
			form.setYwlxrtel(entity.getYwlxrtel());
			form.setGszcdjh(entity.getGszcdjh());
			form.setGszcdjyxq(entity.getGszcdjyxq());
			form.setQydlyszh(entity.getQydlyszh());
			form.setQydlyszyxq(entity.getQydlyszyxq());
			form.setQyid(entity.getQyid());
			form.setCls(entity.getCls());
			form.setTccmj(entity.getTccmj());
			form.setZydm(entity.getZydm());
			//发证有效期的时间转换
			Date startdate=entity.getValidStarttime();
			Date enddate=entity.getValidEndtime();
			if(startdate!=null){
				String starttime=DateUtilsEX.dateFormate(startdate,"yyyy-MM-dd");
				String[] times=starttime.split("-");
				form.setStartYear(times[0]);
				form.setStartMonth(times[1]);
				form.setStartDay(times[2]);
			}
			if(enddate!=null){
				String endtime=DateUtilsEX.dateFormate(enddate,"yyyy-MM-dd");
				String[] times=endtime.split("-");
				form.setEndYear(times[0]);
				form.setEndMonth(times[1]);
				form.setEndDay(times[2]);
			}
			WfBusClientBaseInfoConvertor.convertVoToForm(entity, form);
			
			return form;
		}else
			return null;
	}
	
	public static List<YwYnJzfqwczcJbxxForm> convertVoListToFormList(List<YwYnJzfqwczcJbxx> ywYnJzfqwczcJbxxList) {
		if(ywYnJzfqwczcJbxxList != null && ywYnJzfqwczcJbxxList.size() > 0) {
			List<YwYnJzfqwczcJbxxForm> ywYnJzfqwczcJbxxFormList = new ArrayList();
			for(int i=0; i<ywYnJzfqwczcJbxxList.size(); i++) {
				ywYnJzfqwczcJbxxFormList.add(convertVoToForm(ywYnJzfqwczcJbxxList.get(i)));
			}
			return ywYnJzfqwczcJbxxFormList;
		}
		return null;
	}
	public static void convertFormToQyxxForm(YwYnJzfqwczcJbxxForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();
        
        new DozerBeanMapper().map(form, qyxxForm);
        qyxxForm.setId(form.getQyid());
    }
	
	public static void convertFormToVo(YwYnJzfqwczcJbxxForm form, YwYnJzfqwczcJbxx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwYnJzfqwczcJbxx();
        
        new DozerBeanMapper().map(form, entity);
    }
	
	public static List<Map> convertVoListToMapList(List<YwYnJzfqwczcJbxx> ywYnJzfqwczcJbxxList) {
		if(ywYnJzfqwczcJbxxList != null && ywYnJzfqwczcJbxxList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<ywYnJzfqwczcJbxxList.size(); i++) {
				YwYnJzfqwczcJbxx entity = ywYnJzfqwczcJbxxList.get(i);
				Map<String, String> map = new HashMap();

				map.put("czzFzr", entity.getCzzFzr());
				map.put("czzFzsj",DateUtils.dateTimeToString(entity.getCzzFzsj(), "yyyy-MM-dd"));
				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("acceptNo", entity.getAcceptNo());
				map.put("sqDate", DateUtils.dateTimeToString(entity.getSqDate(), "yyyy-MM-dd"));
				map.put("qymc", entity.getQymc());
				map.put("frxm", entity.getFrxm());
				map.put("frphone", entity.getFrphone());
				map.put("address", entity.getAddress());
				map.put("sqsx", entity.getSqsx());
				map.put("czzh", entity.getCzzh());
				map.put("qymcSimpl", entity.getQymcSimpl());
				map.put("post", entity.getPost());
				map.put("tel", entity.getQyphone());
//				map.put("frName", entity.getFrName());
				map.put("frTel", entity.getFrTel());
				map.put("ywlxr", entity.getYwlxr());
				map.put("ywlxrtel", entity.getYwlxrtel());
				map.put("gszcdjh", entity.getGszcdjh());
				map.put("gszcdjyxq", DateUtils.dateTimeToString(entity.getGszcdjyxq(), "yyyy-MM-dd"));
				map.put("qydlyszh", entity.getQydlyszh());
				map.put("qydlyszyxq", DateUtils.dateTimeToString(entity.getQydlyszyxq(), "yyyy-MM-dd"));
				map.put("cls", entity.getCls() == null ? "" : entity.getCls().toString());
				map.put("tccmj", entity.getTccmj());
				map.put("zydm", entity.getZydm());
				map.put("sendNotice", entity.getSendNotice());
				map.put("yslNo", entity.getYslNo());
				map.put("businessCode", entity.getBusinessCode());
				map.put("approvalNo", entity.getApprovalNo());
				map.put("ysl", entity.getYsl() == null ? "" : entity.getYsl().toString());
				map.put("qsrq", DateUtils.dateTimeToString(entity.getQsrq(), "yyyy-MM-dd"));
				map.put("zydm", entity.getZydm());
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<YwYnJzfqwczcJbxx> convertFormListToVoList(List<YwYnJzfqwczcJbxxForm> ywYnJzfqwczcJbxxFormList) {
		if(ywYnJzfqwczcJbxxFormList != null && ywYnJzfqwczcJbxxFormList.size() > 0) {
			List<YwYnJzfqwczcJbxx> ywYnJzfqwczcJbxxList = new ArrayList();
			for(int i=0; i<ywYnJzfqwczcJbxxFormList.size(); i++) {
				YwYnJzfqwczcJbxx ywYnJzfqwczcJbxx = new YwYnJzfqwczcJbxx();
				convertFormToVo(ywYnJzfqwczcJbxxFormList.get(i), ywYnJzfqwczcJbxx);
				ywYnJzfqwczcJbxxList.add(ywYnJzfqwczcJbxx);
			}
			return ywYnJzfqwczcJbxxList;
		}
		return null;
	}
	
	public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, YwYnJzfqwczcJbxxForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new YwYnJzfqwczcJbxxForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQyid(qyxxForm.getId());
    }
	
	public static void convertFormToYwYnJzfqwczcJbxxForFx(YwYnJzfqwczcJbxxForm form, YwYnJzfqwczcJbxxForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwYnJzfqwczcJbxxForFx();        
        new DozerBeanMapper().map(form, entity);
    }
}